package com.flyme.excel.validator;

/**
 * Created by lijizhong on 2017/12/15.
 */

import com.ycc.vins.excel.ExcelCellValidator;
import com.ycc.vins.util.ValidateResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class LegalPayNoValidator implements ExcelCellValidator{

    final Pattern p = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{1,20}$");
    @Nullable
    @Override
    public ValidateResult apply(String s) {

        if (StringUtils.isBlank(s)) {
            return ValidateResult.pass();
        }
        Matcher m = p.matcher(s);
        if (!m.find()) {
            return ValidateResult.notPass("格式不正确(正确的为字母+数字，最多20位字符)");
        }
        return ValidateResult.pass();
    }
}
